<?php
class Cu{

    public static function curl_post($url, $data,$user='',$pass='') {

        $post_data= http_build_query($data);
        $post_data=  urldecode($post_data);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_USERPWD, "{$user}:{$pass}");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $res = curl_exec($ch);
        curl_close($ch);
        return $res;
    }

    public static function curl($url, $data = array(), $type = 'get') {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        if ($type == 'post') {
            $req = http_build_query($data);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
        } else {
            if (!empty($data)) {
                $url = $url . '?' . http_build_query($data);
                $url = urldecode($url);
            }
            curl_setopt($ch, CURLOPT_URL, $url);
        }
        if (substr($url, 0, 5) == 'https') {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        }
        $res = curl_exec($ch);
        curl_close($ch);
        return $res;
    }
}
?>